package com.rrd.dw.mr.gzip.kafka;

import java.io.IOException;
import java.util.Date;
import java.util.regex.Pattern;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import com.rrd.dw.utils.DateUtil;
import com.rrd.dw.utils.MD5Util;
import com.ucredit.babel.common.kafka.CrawlResult;
import com.ucredit.babel.common.model.Job;
import com.ucredit.babel.common.model.xwbank.XwbankData;
import com.ucredit.babel.common.model.xwbank.XwbankApproval;

/**
 *
 * @author zhangjunjian
 */
@Deprecated
public class XwBankParse {
    public static final String CRT001 =  "\001";
    public static final Pattern CRT001_PATTERN =  Pattern.compile("\001");
    private String job_id ="";
    private String timestamstr="";
    private StringBuilder sb = new StringBuilder(500);
    private  Text val = new Text();
    private  Text key= new Text();
    /**
     * 新网银行风控结果数据
     * @param xinyanradarRecord
     * @throws InterruptedException
     * @throws IOException
     */
    public  void parseXwBank(Context context,XwbankApproval xwbankApproval,String successful) throws IOException, InterruptedException{
        new StringBuilder(200);
        Job job = xwbankApproval.getJob();
        XwbankData data = xwbankApproval.getData();

        sb.delete(0,sb.length());
        //job_id
        this.job_id = job.getJobID()==null?"":job.getJobID();
        this.timestamstr=xwbankApproval.getTimestamp()==null?"":DateUtil.formateDateStr(new Date(xwbankApproval.getTimestamp()));
        sb.append(job_id).append(CRT001).append(timestamstr).append(CRT001).append(xwbankApproval.getIdNumber()).append(CRT001);
        //响应http状态 "name", "certtype",  "reason", "createtype","data"
        sb.append(job.getSystemID()==null?"":job.getSystemID()).append(CRT001);

        sb.append(data.getDataJson()==null?"":data.getDataJson()).append(CRT001);
        //
        sb.append(data.getColumnFamilyName()==null?"":data.getColumnFamilyName());

        key.set("xwbank_data");
        val.set(sb.toString().replace("\n", " "));
        context.write(key, val);
    }


}
